#!/bin/bash
DOCKER_IMAGE_HUB=$1
DOCKER_IMAGE_LIB=$2
DOCKER_IMAGE_NAME=$3
DOCKER_USERNAME=$4
DOCKER_PASSWORD=$5         

if [ ! $1 ]; then
    DOCKER_BUILD_WORKDIR='.'
fi
DOCKER_BUILD_FILE=$6
DOCKER_BUILD_WORKDIR=$7
DOCKER_IMAGE_VERSION=$8



echo $DOCKER_IMAGE_HUB $DOCKER_IMAGE_LIB $DOCKER_IMAGE_NAME  $DOCKER_USERNAME $DOCKER_PASSWORD $DOCKER_BUILD_FILE  $DOCKER_BUILD_WORKDIR

DOCKER_REMOTE_IMAGE=${DOCKER_IMAGE_HUB}/${DOCKER_IMAGE_LIB}/${DOCKER_IMAGE_NAME}
echo $DOCKER_REMOTE_IMAGE
#docker login ccr.ccs.tencentyun.com --username=$DOCKER_USERNAME --password=$DOCKER_PASSWORD
echo docker build -f ${DOCKER_BUILD_FILE} -t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} ${DOCKER_BUILD_WORKDIR}

docker build -f ${DOCKER_BUILD_FILE} -t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} ${DOCKER_BUILD_WORKDIR}
docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} ${DOCKER_REMOTE_IMAGE}:${DOCKER_IMAGE_VERSION} 
docker push ${DOCKER_REMOTE_IMAGE}:${DOCKER_IMAGE_VERSION} 
if [ $? -eq 0 ]; then
 echo "push Success"
else 
 echo "push failed"
fi
docker rmi ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}
docker rmi ${DOCKER_REMOTE_IMAGE}:${DOCKER_IMAGE_VERSION} 